package org.example.smartbuy.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.example.smartbuy.entity.Orders;
import org.example.smartbuy.mapper.OrdersMapper;
import org.example.smartbuy.service.IOrdersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Smarty Buy
 * @since 2024-11-18
 */
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements IOrdersService {
    @Autowired
    private OrdersMapper ordersMapper;

    @Override
    public List<Orders> listById(int userId) {
        QueryWrapper<Orders> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return ordersMapper.selectList(queryWrapper);
    }

    @Override
    public Orders getById(int id) {
        return ordersMapper.selectById(id);
    }

    @Override
    public Orders add(Orders orders) {
        ordersMapper.insert(orders);
        return orders;
    }

    @Override
    public Orders update(Orders orders) {
        ordersMapper.updateById(orders);
        return orders;
    }

    @Override
    public void delete(int id) {
        ordersMapper.deleteById(id);
    }
}
